import java.util.*;
public class StudentTest {
    public static void main(String args[]) {
        List<Student> list = new LinkedList<Student>();
        list.add(new Student("20165321","谢沛良",'m',18,90,87,88));
        list.add(new Student("20165322","王瑶佳",'f',18,90,90,89));
        list.add(new Student("20165323","杨金川",'m',18,89,91,80));
        list.add(new Student("20165324","何春江",'m',18,92,88,80));
        list.add(new Student("20165325","李东骏",'m',18,86,84,80));
        Iterator<Student> iter=list.iterator();
        System.out.println("排序前，链表中的数据");
        while (iter.hasNext()) {
            Student stu=iter.next();
            System.out.println(stu.getId()+" "+stu.getName()+" "+stu.getSex()+" "+stu.getComputer_score()+" "+stu.getEnglish_score()+" "+stu.getMaths_score()+" "+stu.getTotalScore()+" "+stu.getAveScore());
        }
        Collections.sort(list, new Comparator<Student>() {
            @Override
            public int compare(Student o1, Student o2) {
                Student st1=(Student)o1;
                Student st2=(Student)o2;
                return (Integer.parseInt(st1.getId())-Integer.parseInt(st2.getId()));
            }
        });
        System.out.println("输出按学号排序后的链表");
        iter=list.iterator();
        while (iter.hasNext()) {
            Student stu=iter.next();
            System.out.println(stu.getId()+" "+stu.getName()+" "+stu.getSex()+" "+stu.getComputer_score()+" "+stu.getEnglish_score()+" "+stu.getMaths_score()+" "+stu.getTotalScore()+" "+stu.getAveScore());
        }

        Collections.sort(list, new Comparator<Student>() {
            @Override
            public int compare(Student o1, Student o2) {
                Student st1 = (Student)o1;
                Student st2 = (Student)o2;
                return (int) (st2.getTotalScore()-st1.getTotalScore());
            }
        });
        System.out.println("输出按总分排序后的链表");
        iter=list.iterator();
        while (iter.hasNext()) {
            Student stu=iter.next();
            System.out.println(stu.getId()+" "+stu.getName()+" "+stu.getSex()+" "+stu.getComputer_score()+" "+stu.getEnglish_score()+" "+stu.getMaths_score()+" "+stu.getTotalScore()+" "+stu.getAveScore());
        }

    }

}